<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:p="http://primefaces.org/ui"
                 template="/template/mainTemplate.xhtml"
                 xmlns:x="http://xpert.com/faces"
                 xmlns:xc="http://java.sun.com/jsf/composite/xpert/components">
    <ui:param name="title" value="#{msg['country.list']}" />
    <ui:define name="body">
        <ui:include src="menuCountry.xhtml" />
        <h:form id="formListCountry">
            <xc:modalMessages/>
            <p:dataTable paginator="true" rows="10" rowsPerPageTemplate="10,20,30" paginatorPosition="bottom" emptyMessage="#{xmsg['noRecordFound']}"
                         var="country" rowIndexVar="index" widgetVar="dataTableCountryWidget"
                         value="#{countryMB.dataModel}" lazy="true" >
                <p:column style="text-align: center;">
                    <f:facet name="header">
                        <p:commandButton onclick="dataTableCountryWidget.filter()" type="button" icon="ui-icon-refresh" />
                    </f:facet>
                    <h:outputText value="#{index+1}"/>
                </p:column>
                <p:column headerText="#{msg['country.name']}" sortBy="#{country.name}"
                          filterBy="#{country.name}"   >
                        <h:outputText value="#{country.name}"/>
                </p:column>
                <p:column style="text-align: center;">
                    <f:facet name="header">
                        <xc:legends detail="true" edit="true" delete="true"/>
                    </f:facet>
                    <p:commandButton oncomplete="widgetCountryDetail.show();"  icon="ui-icon-zoomin" 
                                     process="@form" update=":formDetailCountry" title="#{xmsg['detail']}" >
                        <f:setPropertyActionListener value="#{country}" target="#{countryMB.entity}" />
                    </p:commandButton>
                    <x:securityArea rolesAllowed="country.create">
                        <p:button icon="ui-icon-pencil" outcome="createCountry" title="#{xmsg['edit']}">
                            <f:param name="id" value="#{country.id}" />
                        </p:button>
                    </x:securityArea>
                    <x:securityArea rolesAllowed="country.delete">
                        <p:commandButton icon="ui-icon-trash" title="#{xmsg['delete']}" process="@form" update="@form" 
                                         action="#{countryMB.delete}" >
                            <f:setPropertyActionListener value="#{country.id}" target="#{countryMB.id}" />
                            <x:confirmation message="#{xmsg['confirmDelete']} - #{country}" />
                        </p:commandButton>
                    </x:securityArea>
                </p:column>
                <f:facet name="footer">
                    <x:securityArea rolesAllowed="country.audit">
                        <xc:auditDelete for="#{countryMB.entityClass}"/>
                    </x:securityArea>
                </f:facet>
            </p:dataTable>
        </h:form>

        <p:dialog widgetVar="widgetCountryDetail" header="#{msg['country.detail']}" appendToBody="true" modal="true" height="500" width="800">
            <ui:include src="detailCountry.xhtml" />
        </p:dialog>
    </ui:define>
</ui:composition>